package com.ycdx.impms.impl;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

import com.ycdx.impms.pojo.Ryxx;
import com.ycdx.impms.utils.DBPool;

public class RyxxImpl {
	
	static Logger logger = Logger.getLogger(RyxxImpl.class.getName());
	
	/**
	 * 分页查询人员信息
	 * @param start
	 * @param number
	 * @param area
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static ArrayList<Ryxx> getRyxxList(int start,int number,String area){
		ArrayList<Ryxx> result = new ArrayList<Ryxx>();
		String sql = "";
		if(area.equals("全区")){
			//全区权限
			sql = "select * from tb_ryxx order by dw,id limit ?,? ";
		}else{
			sql = "select * from tb_ryxx where dw = '"+area+"' order by dw,id limit ?,?";
		}
		//System.out.println(sql);
		Object[] params = {start,number};
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		
		try {
			result = (ArrayList<Ryxx>) qr.query(conn, sql, new BeanListHandler(Ryxx.class),params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("RyxxImpl.class-getRyxxList()-数据库操作失败！");
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-getRyxxList()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 根据地区查询出人员信息用于导出excel
	 * @param area
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static List<Ryxx> queryByArea(String area) {
		ArrayList<Ryxx> result = new ArrayList<Ryxx>();
		String sql = "";
		if(area.equals("全区")){
			//全区权限
			sql = "select * from tb_ryxx;";
		}else{
			sql = "select * from tb_ryxx where dw = '"+area+"';";
		}
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		
		try {
			result = (ArrayList<Ryxx>) qr.query(conn, sql, new BeanListHandler(Ryxx.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("RyxxImpl.class-queryByArea()-数据库操作失败！");
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-queryByArea()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 查询记录总数
	 * @param area
	 * @return
	 */
	public static int getCount(String area){
		Map<String,Object> totalMap = new HashMap<String, Object>();
		int total ;
		String sql = "";
		if(area.equals("全区")){
			//全区权限
			sql = "select count(*) total from tb_ryxx;";
		}else{
			sql = "select count(*) total from tb_ryxx where dw = '"+area+"';";
		}
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		try {
			totalMap = (HashMap<String, Object>)qr.query(conn,sql, new MapHandler());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("RyxxImpl.class-getCount()-数据库操作失败！");
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-getCount()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//total = Integer.parseInt((String)totalMap.get("total"));
		total = Integer.parseInt( totalMap.get("total").toString());
		//System.out.println(total);
		return total;
	}
	
	/**
	 * 查询符合查询条件记录总数
	 * @param area
	 * @param name
	 * @return
	 */
	public static int getQueryResultCount(String area,String name){
		Map<String,Object> totalMap = new HashMap<String, Object>();
		int total ;
		String sql = "";
		if(area.equals("全区")){
			//全区权限
			sql = "select count(*) total from tb_ryxx where xm like ? order by dw,id;";
		}else{
			sql = "select count(*) total from tb_ryxx where dw = '"+area+"' and xm like ? order by dw,id;";
		}
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		Object[] params = {"%"+name+"%"};
		try {
			totalMap = (HashMap<String, Object>)qr.query(conn,sql, new MapHandler(),params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("RyxxImpl.class-getQueryResultCount()-数据库操作失败！");
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-getQueryResultCount()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//total = Integer.parseInt((String)totalMap.get("total"));
		total = Integer.parseInt( totalMap.get("total").toString());
		//System.out.println(total);
		return total;
	}
	
	/**
	 * 添加人员信息
	 * @param ryxx
	 * @return
	 */
	public static int addRyxx(Ryxx ryxx){
		String sql = "insert into tb_ryxx (" +
				"dw," 		+ "xm," 		+ "xb," 		+ "bm_xc," +
				"bm_zj," 	+ "rysx," 		+ "dwgsmc," 	+
				"gznr," 	+ "sfbzz," 		+ "fdfj," 		+
				"fwyhs," 	+ "fwyhs_kd," 	+ "fwyhs_itv," 	+
				"xl," 		+ "sfzh," 		+ "sjhm," 		+
				"zwjndj," 	+ "ftthjndj," 	+ "zt," 		+	
				"rzsj," 	+ "lzsj," 		+ "ry," 			+ "bz," + "csrq" +
				") values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
		Object[] params = {ryxx.getDw(),ryxx.getXm(),ryxx.getXb(),ryxx.getBm_xc()
				,ryxx.getBm_zj(),ryxx.getRysx(),ryxx.getDwgsmc()
				,ryxx.getGznr(),ryxx.getSfbzz(),ryxx.getFdfj()
				,ryxx.getFwyhs(),ryxx.getFwyhs_kd(),ryxx.getFwyhs_itv()
				,ryxx.getXl(),ryxx.getSfzh(),ryxx.getSjhm()
				,ryxx.getZwjndj(),ryxx.getFtthjndj(),ryxx.getZt()
				,ryxx.getRzsj(),ryxx.getLzsj(),ryxx.getRy(),ryxx.getBz(),ryxx.getCsrq()};
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		
		int flag = 0;
		try {
			flag = qr.update(conn,sql, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			logger.error("RyxxImpl.class-addRyxx()-数据库操作失败！");
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-addRyxx()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return flag;
	}
	/**
	 * 更新指定id的人员信息
	 * @param id
	 * @param ryxx
	 * @return
	 */
	public static int updateRyxx(int id,Ryxx ryxx){
		String sql = "update tb_ryxx set " +
						"dw=?," 		+ "xm=?," 			+ "xb=?," 			+ "bm_xc=?," +
						"bm_zj=?," 		+ "rysx=?," 		+ "dwgsmc=?," 		+
						"gznr=?," 		+ "sfbzz=?," 		+ "fdfj=?," 		+
						"fwyhs=?," 		+ "fwyhs_kd=?," 	+ "fwyhs_itv=?," 	+
						"xl=?," 		+ "sfzh=?," 		+ "sjhm=?," 		+
						"zwjndj=?," 	+ "ftthjndj=?," 	+ "zt=?," 			+	
						"rzsj=?," 		+ "lzsj=?," 		+ "ry=?," 			+ "bz=?," +  "csrq=?" +
						"where id=?;";
		Object[] params = {ryxx.getDw(),ryxx.getXm(),ryxx.getXb(),ryxx.getBm_xc()
				,ryxx.getBm_zj(),ryxx.getRysx(),ryxx.getDwgsmc()
				,ryxx.getGznr(),ryxx.getSfbzz(),ryxx.getFdfj()
				,ryxx.getFwyhs(),ryxx.getFwyhs_kd(),ryxx.getFwyhs_itv()
				,ryxx.getXl(),ryxx.getSfzh(),ryxx.getSjhm()
				,ryxx.getZwjndj(),ryxx.getFtthjndj(),ryxx.getZt()
				,ryxx.getRzsj(),ryxx.getLzsj(),ryxx.getRy(),ryxx.getBz(),ryxx.getCsrq(),id};
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		
		int flag = 0;
		try {
			flag = qr.update(conn,sql, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			logger.error("RyxxImpl.class-updateRyxx()-数据库操作失败！");
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-updateRyxx()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return flag;
	}
	
	/**
	 * 根据id删除人员信息
	 * @param id
	 * @return
	 */
	public static int removeRyxx(int id){
		String sql = "delete from tb_ryxx where id=?";
		Object[] params = {id};
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		
		int flag = 0;
		try {
			flag = qr.update(conn,sql, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			logger.error("RyxxImpl.class-removeRyxx()-数据库操作失败！");
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-removeRyxx()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return flag;
	}
	
	@SuppressWarnings("unchecked")
	public static List<Ryxx> queryByName(int start,int number,String area,String name){
		ArrayList<Ryxx> result = new ArrayList<Ryxx>();
		String sql = "";
		if(area.equals("全区")){
			//全区权限
			sql = "select * from tb_ryxx where xm like ? order by dw,id limit ?,?;";
		}else{
			sql = "select * from tb_ryxx where dw = '"+area+"' and xm like ? order by dw,id limit ?,?;";
		}
		Connection conn = DBPool.getInstance().getConnection();
		QueryRunner qr = new QueryRunner();
		Object[] params = {"%"+name+"%",start,number};
		try {
			result = (ArrayList<Ryxx>) qr.query(conn, sql, new BeanListHandler(Ryxx.class),params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("RyxxImpl.class-queryByName()-数据库操作失败！");
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				logger.error("RyxxImpl.class-queryByName()-连接关闭失败！");
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 根据list导出excel
	 * @param allRequests
	 * @return
	 */
	public static InputStream getExcelStream(List<Ryxx> allRyxx) {
	  HSSFWorkbook wb = new HSSFWorkbook();//创建一个工作间
	  HSSFSheet sheet = wb.createSheet("sheet1");//创建一个sheet
	  HSSFRow row = sheet.createRow(0);//创建一行
	  //设置列宽
	  
	  sheet.setColumnWidth(0, 1500);
	  sheet.setColumnWidth(1, 1500);
	  sheet.setColumnWidth(2, 2000);
	  sheet.setColumnWidth(3, 1500);
	  sheet.setColumnWidth(4, 6000);
	  sheet.setColumnWidth(5, 5000);
	  sheet.setColumnWidth(6, 2500);
	  sheet.setColumnWidth(7, 6000);
	  sheet.setColumnWidth(8, 5000);
	  sheet.setColumnWidth(9, 3000);
	  sheet.setColumnWidth(10, 3000);
	  sheet.setColumnWidth(11, 4000);
	  sheet.setColumnWidth(12, 4000);
	  sheet.setColumnWidth(13, 4000);
	  sheet.setColumnWidth(14, 2000);
	  sheet.setColumnWidth(15, 5000);
	  sheet.setColumnWidth(16, 3000);
	  sheet.setColumnWidth(17, 3000);
	  sheet.setColumnWidth(18, 3500);
	  sheet.setColumnWidth(19, 3500);
	  sheet.setColumnWidth(20, 2000);
	  sheet.setColumnWidth(21, 4000);
	  sheet.setColumnWidth(22, 4000);
	  sheet.setColumnWidth(23, 5000);
	  sheet.setColumnWidth(24, 5000);
	  
	  
	  // 设置字体 
      HSSFFont font = wb.createFont();
      font.setFontHeightInPoints(( short ) 10 ); // 字体高度 
      font.setColor(HSSFFont.COLOR_NORMAL); // 字体颜色 
      font.setFontName( "宋体 " ); // 字体 
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 宽度 
	  
	  //生成一个样式
      HSSFCellStyle style = wb.createCellStyle();
      
      
      //设置这些样式      
      
      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
      style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
      
      //新建标题样式
      HSSFCellStyle titlestyle = wb.createCellStyle();
      titlestyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
      titlestyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      titlestyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      titlestyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      titlestyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
      titlestyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
      titlestyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
      titlestyle.setFont(font);
      
      HSSFCell cell = row.createCell(0);//创建这行的第一个元素.从0开始
	  cell.setCellValue(new HSSFRichTextString("编号"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(1);//同上,不多解释了
	  cell.setCellValue(new HSSFRichTextString("单位"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(2);
	  cell.setCellValue(new HSSFRichTextString("姓名"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(3);
	  cell.setCellValue(new HSSFRichTextString("性别"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(4);
	  cell.setCellValue(new HSSFRichTextString("部门名称"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(5);
	  cell.setCellValue(new HSSFRichTextString("支局名称"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(6);
	  cell.setCellValue(new HSSFRichTextString("人员属性"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(7);
	  cell.setCellValue(new HSSFRichTextString("代维公司名称"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(8);
	  cell.setCellValue(new HSSFRichTextString("工作内容"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(9);
	  cell.setCellValue(new HSSFRichTextString("是否班组长"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(10);
	  cell.setCellValue(new HSSFRichTextString("分等分级"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(11);
	  cell.setCellValue(new HSSFRichTextString("服务用户数"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(12);
	  cell.setCellValue(new HSSFRichTextString("服务宽带用户数"));
	  cell.setCellStyle(titlestyle);	  
	  
	  cell = row.createCell(13);
	  cell.setCellValue(new HSSFRichTextString("服务ITV用户数"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(14);
	  cell.setCellValue(new HSSFRichTextString("学历"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(15);
	  cell.setCellValue(new HSSFRichTextString("身份证号"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(16);
	  cell.setCellValue(new HSSFRichTextString("出生日期"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(17);
	  cell.setCellValue(new HSSFRichTextString("手机号码"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(18);
	  cell.setCellValue(new HSSFRichTextString("装维技能等级"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(19);
	  cell.setCellValue(new HSSFRichTextString("FTTH技能等级"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(20);
	  cell.setCellValue(new HSSFRichTextString("状态"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(21);
	  cell.setCellValue(new HSSFRichTextString("入职时间"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(22);
	  cell.setCellValue(new HSSFRichTextString("离职时间"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(23);
	  cell.setCellValue(new HSSFRichTextString("荣誉"));
	  cell.setCellStyle(titlestyle);
	  
	  cell = row.createCell(24);
	  cell.setCellValue(new HSSFRichTextString("备注"));
	  cell.setCellStyle(titlestyle);
	  
	  //循环,将下面几行的数据取出来放入这个sheet中
	  for(int i = 0 ; i < allRyxx.size() ; i++)
	  {
	   Ryxx ryxx = allRyxx.get(i);
	   row = sheet.createRow(i+1);
	   
	   cell = row.createCell(0);
	   cell.setCellValue(ryxx.getId());
	   cell.setCellStyle(style);
	   
	   cell = row.createCell(1);
	   cell.setCellValue(new HSSFRichTextString(ryxx.getDw()));
	   cell.setCellStyle(style);
	   
	   cell = row.createCell(2);
	   cell.setCellValue(new HSSFRichTextString(ryxx.getXm()));
	   cell.setCellStyle(style);
	   
	   cell = row.createCell(3);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getXb()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(4);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getBm_xc()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(5);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getBm_zj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(6);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getRysx()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(7);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getDwgsmc()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(8);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getGznr()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(9);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getSfbzz()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(10);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getFdfj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(11);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getFwyhs()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(12);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getFwyhs_kd()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(13);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getFwyhs_itv()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(14);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getXl()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(15);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getSfzh()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(16);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getCsrq()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(17);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getSjhm()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(18);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getZwjndj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(19);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getFtthjndj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(20);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getZt()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(21);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getRzsj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(22);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getLzsj()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(23);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getRy()));
	  cell.setCellStyle(style);
	  
	  cell = row.createCell(24);
	  cell.setCellValue(new HSSFRichTextString(ryxx.getBz()));
	  cell.setCellStyle(style);
	   
	  }
//	  for(int i=0;i<=20;i++){
//		  sheet.autoSizeColumn(i);
//	  }
	  ByteArrayOutputStream os=new ByteArrayOutputStream();  
      try {  
          wb.write(os);  
            
      } catch (IOException e) {  
          e.printStackTrace();  
      }  
      byte[] bytes=os.toByteArray();  
      InputStream is=new ByteArrayInputStream(bytes);  
      return is;  
	 }
	
}
